toNonZeroIntOrThrow
Returns this number as a NonZeroInt, which may involve rounding or truncation, or throws IllegalArgumentException if this number equals zero.
var result: NonZeroInt = 1.toNonZeroIntOrThrow()
println(result) // 1
0.toNonZeroIntOrThrow() // IllegalArgumentException
Content copied to clipboard
You can use the toNonZeroIntOrNull function for returning null
instead of throwing an IllegalArgumentException when this number equals zero.